﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Phone.Shell;
using Coding4Fun.Phone.Controls;

namespace BudgetManager.Domain
{
    public class Category
    {
        private static List<Category> _categories = new List<Category>  { new Category { Name = "Alimentação" }, new Category { Name = "Automóvel" }, new Category { Name = "Eletricidade" }, new Category { Name = "Água" }, new Category { Name = "Telefone" },
                new Category { Name = "Faculdade" }, new Category { Name = "Vestuário" },  new Category { Name = "Abono" }, new Category { Name = "Mesada" }, new Category { Name = "Salário" }, new Category { Name = "Outros" } };


        
        public String Name { get; set; }

        public override string ToString()
        {
            return Name;
        }
        public static void makeToast(string toastText)
        {
            //Make a new toast with content "text"
           ToastPrompt toast = new ToastPrompt();
            toast.Title = "Toast Title: ";
            toast.Message = toastText;
            ToastPrompt toast1 = new ToastPrompt();
            toast1.Title = "Toast Title: ";
            toast1.Message = toastText;
            ToastPrompt toast2 = new ToastPrompt();
            toast2.Title = "Toast Title: ";
            toast2.Message = toastText;
            ToastPrompt toast3 = new ToastPrompt();
            toast3.Title = "Toast Title: ";
            toast3.Message = toastText;
            //toast.Completed += toast_comp;

            toast.Show();
            toast1.Show();
            toast2.Show();
            toast3.Show();
        }

        public static Category addCategory(String name)
        {
            Category category = new Category { Name = name };
            _categories.Add(category);
            
            return category;
        }

        public static void DeleteCategory(String name)
        {
            Category category = readCategory(name, _categories);
            _categories.Remove(category);
        }


        public static List<Category> readAllIncomesCategories()
        {
            return new List<Category> { new Category { Name = "Abono" }, new Category { Name = "Mesada" }, new Category { Name = "Salário" } , new Category { Name = "Outros" } };
        }
        public static List<Category> ReadAllCategories()
        {
            return _categories;
        }
        public static List<Category> ReadAllCategoriesOrderByName()
        {
            return ReadAllCategories().OrderBy(cat => cat.Name).ToList(); ;
        }
        
        public static Category ReadDefaultCategory()
        {
            return new Category { Name = "Não Categorizado" };
        }
        public static Category readIncomeCategoryByName(String name){
            return readCategory(name, Category.readAllIncomesCategories());
        }
        public static Category readOutcomeCategoryByName(String name)
        {
            return readCategory(name, ReadAllCategories());
        }

        private static Category readCategory(String name, List<Category> categories)
        {
            foreach (Category category in categories)
            {
                if(category.Name.Equals(name)){
                    return category;
                }
            }
            return null;
        }
    }

}
